package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.DetailsExchangeDao;
import com.fdb.efp.nls.service.domain.DetailsExchange;
import com.fdb.efp.nls.service.facade.DetailsExchangeService;
import com.fdb.efp.nls.service.vo.DetailsExchangeVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 交易明细类型配置的Service实现类
 * </p>
 * @author yusys
 * @createDate 2018-07-09 15:29:26
 */
@Service("detailsExchangeService")
public class DetailsExchangeServiceImpl implements DetailsExchangeService, FrameworkService {
    
    private static Logger logger = LoggerFactory.getLogger(DetailsExchangeServiceImpl.class);
    
    @Autowired
    private DetailsExchangeDao detailsExchangeDao;
    
    @Override
    public int insertDetailsExchange(DetailsExchangeVO inDetailsExchangeVo) {
        logger.debug("当前新增数据为：" + inDetailsExchangeVo.toString());
        int count = 0;
        try {
            DetailsExchange detailsExchange = new DetailsExchange();
            beanCopy(inDetailsExchangeVo, detailsExchange);
            count = detailsExchangeDao.insertDetailsExchange(detailsExchange);
        } catch (Exception e) {
            logger.error("新增数据发生异常！", e);
            count = -1;
        }
        logger.debug("当前新增数据条数为：" + count);
        return count;
    }
    
    @Override
    public int deleteByPk(DetailsExchangeVO inDetailsExchangeVo) {
        logger.debug("当前删除数据条件为：" + inDetailsExchangeVo.toString());
        int count = 0;
        try {
            DetailsExchange detailsExchange = new DetailsExchange();
            beanCopy(inDetailsExchangeVo, detailsExchange);
            count = detailsExchangeDao.deleteByPk(detailsExchange);
        } catch (Exception e) {
            logger.error("删除数据发生异常！", e);
            count = -1;
        }
        logger.debug("根据条件：" + inDetailsExchangeVo + "删除的数据条数为" + count);
        return count;
    }
    
    @Override
    public int updateByPk(DetailsExchangeVO inDetailsExchangeVo) {
        logger.debug("当前修改数据为：" + inDetailsExchangeVo.toString());
        int count = 0;
        try {
            DetailsExchange detailsExchange = new DetailsExchange();
            beanCopy(inDetailsExchangeVo, detailsExchange);
            count = detailsExchangeDao.updateByPk(detailsExchange);
        } catch (Exception e) {
            logger.error("修改数据发生异常！", e);
            count = -1;
        }
        logger.debug("根据条件：" + inDetailsExchangeVo + "修改的数据条数为" + count);
        return count;
    }
    
    @Override
    public DetailsExchangeVO queryByPk(DetailsExchangeVO inDetailsExchangeVo) {
        logger.debug("当前查询参数信息为：" + inDetailsExchangeVo);
        try {
            DetailsExchange detailsExchange = new DetailsExchange();
            beanCopy(inDetailsExchangeVo, detailsExchange);
            DetailsExchange querydetailsExchange = detailsExchangeDao.queryByPk(detailsExchange);
            if (Objects.nonNull(querydetailsExchange)) {
                DetailsExchangeVO outDetailsExchangeVo = beanCopy(querydetailsExchange, new DetailsExchangeVO());
                logger.debug("当前查询结果为：" + outDetailsExchangeVo.toString());
                return outDetailsExchangeVo;
            } else {
                logger.debug("当前查询结果为空！");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常！", e);
        }
        return null;
    }
}